<template>
  <div class="StatisticsAll">
    <el-form
      ref="form"
      :model="form"
      label-position="top"
      class="myform"
      size="mini"
    >
      <div>
        <el-form-item label="单号" class="myform-item">
          <el-input
            v-model="form.number"
            placeholder="请输入单号"
            @keyup.enter.native="onSearch"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="审批状态" class="myform-item">
          <el-select v-model="form.status" placeholder="请选择" clearable>
            <el-option
              v-for="item in optionsSP"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="发起时间" class="myform-item">
          <el-date-picker
            clearable
            v-model="form.strtime"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item style="margin-top: 38px">
          <el-button type="primary" @click="onSearch">查询</el-button>
          
        </el-form-item>
      </div>
      <div></div>
    </el-form>
    <el-button type="primary" size="small" plain @click="onInitiate" style="margin-bottom:5px"><i class="el-icon-plus" style="font-weight:600"></i> 发起内购</el-button>
    <el-table :data="tableData" border style="width: 100%" size="mini">
      <el-table-column prop="allocation_number" label="内购单号">
      </el-table-column>
      <el-table-column prop="instance_code" label="审批id"> </el-table-column>
      <el-table-column prop="sku_code" label="SKU">
        <template slot-scope="{ row }">
          <div v-for="(item, index) in row.sku_code" :key="index">
            {{ item.sku_code }}
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="total_num" label="内购总数"> </el-table-column>
      <el-table-column prop="total_price" label="原价金额汇总">
      </el-table-column>
      <el-table-column label="折扣" prop="discount">
      </el-table-column>
      <el-table-column prop="discount_amount" label="折扣金额汇总">
      </el-table-column>
      <el-table-column label="邮寄信息" align="center" prop="wp_user">
        <template slot-scope="{ row }">
          <div v-if="row.wp_user && row.wp_phone && row.wp_address">
            {{ row.wp_user + "，" }} {{ row.wp_phone + "，"
            }}{{ row.wp_province }}{{ row.wp_city }}{{ row.wp_area
            }}{{ row.wp_address }}
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="createtime" label="申请时间"> </el-table-column>
      <el-table-column label="类型" align="types" prop="wp_user">
        <template slot-scope="{ row }">
          <div>
            {{ row.types == "1" ? "转内购" : "内购" }}
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="status" label="审核状态">
        <template slot-scope="{ row }">
          <div
            :style="{
              color:
                row.status == 0
                  ? '#E6A23C'
                  : row.status == 1
                  ? '#67C23A'
                  : row.status == 2
                  ? '#F56C6C'
                  : row.status == 3
                  ? '#909399'
                  : '',
            }"
          >
            {{
              row.status == 0
                ? "审核中"
                : row.status == 1
                ? "已通过"
                : row.status == 2
                ? "已拒绝"
                : row.status == 3
                ? "已撤销"
                : ""
            }}
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="is_push" label="推送状态">
        <template slot-scope="{ row }">
          <div
            :style="{
              color:
                row.is_push == 1
                  ? '#67C23A'
                  : row.is_push == 2
                  ? '#F56C6C'
                  : row.is_push == 3
                  ? '#909399'
                  : '',
            }"
          >
            {{
              row.is_push == 0
                ? "未推送"
                : row.is_push == 1
                ? "成功"
                : row.is_push == 2
                ? "失败"
                : row.is_push == 3
                ? "取消"
                : ""
            }}
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="address" label="操作">
        <template scope="{ row }">
          <el-button type="text" size="default" @click="onLook(row)"
            >查看详情</el-button
          >
          <!-- <el-button
              v-if="row.status == 1"
              style="color: red"
              type="text"
              size="default"
              @click="onCancel(row)"
              >取消</el-button
            > -->
        </template>
      </el-table-column>
    </el-table>
    <pagination
      :form="form"
      :total="total"
      @paginationPostOrderTaskList="postAdminOmsGetAllocationipurchasellist"
    />
  </div>
</template>
  
<script>
import { floatMultiply } from "@/utils/algorithm.js";
import pagination from "@/components/pagination.vue";
import {
  postAdminOmsGetAllocationipurchasellist,
  postAdminAdminOmsCancelAllocation,
} from "@/api";
export default {
  components: { pagination },
  filters: {
    arrString(value) {
      let string = "";
      for (let index = 0; index < value.length; index++) {
        if (index != 0) {
          string = string + "," + value[index].type_no;
        } else {
          string = value[index].type_no;
        }
      }
      return string;
    },
    groupsTitle(e) {
      if (e == 1) return "赠送";
      if (e == 2) return "借出";
      if (e == 3) return "归还";
      return e;
    },
    statusTitle(e) {
      if (e == 0) return "审核中";
      if (e == 1) return "已通过";
      if (e == 2) return "已拒绝";
      if (e == 3) return "已撤销";
      return e;
    },
    is_returnTitle(e) {
      if (e == 0) return "未归还";
      if (e == 1) return "部分归还";
      if (e == 2) return "全部归还";
      return e;
    },
  },
  data() {
    return {
      optionsSP: [
        {
          value: "0",
          label: "审核中",
        },
        {
          value: "1",
          label: "已通过",
        },
        {
          value: "2",
          label: "已拒绝",
        },
        {
          value: "3",
          label: "已撤销",
        },
      ],
      optionsGH: [
        {
          value: "0",
          label: "未归还",
        },
        {
          value: "1",
          label: "部分归还",
        },
        {
          value: "2",
          label: "全部归还",
        },
      ],
      optionsLX: [
        {
          value: "",
          label: "全部",
        },
        {
          value: "1",
          label: "赠送",
        },
        {
          value: "2",
          label: "借出",
        },
      ],
      form: {
        number: "",
        status: "",
        strtime: "",
        endtime: "",
        page: 1,
        size: 10,
      },
      tableData: [],
      total: 0,
    };
  },
  activated() {
    this.postAdminOmsGetAllocationipurchasellist(this.form);
  },
  methods: {
    onInitiate(){
        this.$router.push({
          name: "PDAdminTransfersaddN"
        });
    },
    onCancel(e) {
      let _this = this;
      let data = {
        allocation_number: e.allocation_number,
        order_type: "TRAN",
      };
      this.$confirm("确定取消调拨?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          await postAdminAdminOmsCancelAllocation(data);
          this.postAdminOmsGetAllocationipurchasellist(_this.form);
          this.$message({
            type: "success",
            message: "成功!",
          });
        })
        .catch(() => {});
    },
    onLook(e) {
      if (e.groups == 1) {
        this.$router.push({
          name: "PDAdminTransfersdetailN",
          query: { allocation_number: e.allocation_number },
        });
      } else {
        this.$router.push({
          name: "PDAdminTransfersdetailN",
          query: { allocation_number: e.allocation_number },
        });
      }
    },
    // 审批进度
    onLookRun(id, type, run_id) {
      this.$router.push({ name: "contractrunid", query: { id, type, run_id } });
    },
    async postAdminOmsGetAllocationipurchasellist(data) {
      console.log("data", data);
      this.form = data;
      let form = JSON.parse(JSON.stringify(data));
      console.log("data", data);
      if (form.strtime) {
        form.strtime = `${data.strtime[0]}`;
        form.endtime = `${data.strtime[1]}`;
      } else {
        form.strtime = "";
        form.endtime = "";
      }
      let res = await postAdminOmsGetAllocationipurchasellist(form);
      let arr = res.data
      arr.forEach((e, idx) => {
          e.dzprice = 
            floatMultiply(Number(e.total_price), 0.68)
        });
      this.tableData = arr;
      this.total = Number(res.total);
    },
    onSearch() {
      let { form } = this;
      form.page = 1;
      form.size = 10;
      this.postAdminOmsGetAllocationipurchasellist(form);
    },
  },
};
</script>
  
  <style lang="scss" scoped>
.myform {
  display: flex;
  justify-content: space-between;
  > div {
    display: flex;
  }
  &-item {
    margin-right: 10px;
  }
}
.StatisticsAll {
  background: #fff;
  padding: 10px;
}
</style>